﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GoogleSiteLink
{
    public partial class MainForm : Form
    {
        private List<SiteLinks> LinkControls = new List<SiteLinks>();
        public MainForm()
        {
            InitializeComponent();
        }
        public int myCounter { get; set; }
        private void lbAddSiteLinks_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (myCounter < 10)
            {
                myCounter++;
                if (myCounter == 10)
                {
                    lbAddSiteLinks.Enabled = false;
                }
                this.SuspendLayout();
                this.plSiteLink.SuspendLayout();
                this.Height += 25;
                plSiteLink.Height += 25;
                SiteLinks addSiteLink = new SiteLinks();
                addSiteLink.SiteLinkRemoved += new Action<SiteLinks>(addSiteLink_SiteLinkRemoved);

                addSiteLink.Dock = DockStyle.Bottom;
                Point p = new Point(0,myCounter*25);
                addSiteLink.Location = p;

                this.LinkControls.Add(addSiteLink);
                plSiteLink.Controls.Add(addSiteLink);
                plSiteLink.ResumeLayout();
                this.ResumeLayout();
            }
            else
            {
                return;
            }
        }

        void addSiteLink_SiteLinkRemoved(SiteLinks obj)
        {
            if (this.LinkControls.Contains(obj))
            {
                this.Height -= 25;
                plSiteLink.Height -= 25;
                this.LinkControls.Remove(obj);
                this.plSiteLink.Controls.Remove(obj);
                myCounter--;
                lbCurrentSiteLinks.Text=string.Format(lbCurrentSiteLinks.Text,myCounter.ToString());
                this.lbAddSiteLinks.Enabled = true;
            }
        }
    }
}
